using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using Rotempco.Core.ORM.Objects;
using Rotempco.Core.ORM.Logic;

namespace Rotempco.Core.CSV.Objects
{
    public class CSVParameterMappingContainer<T>
    {
        public List<CSVParameterMapping> CSVParameterMappingList { get; private set; }

        public CSVParameterMappingContainer()
        {
            CSVParameterMappingList = new List<CSVParameterMapping>();
        }

        public void Add<TReturn>(int csvColumnIndex, Expression<Func<T, TReturn>> parameterName, Action<T, string> setParameter = null, Func<string, string> parseCSVString = null)
        {
            Add(csvColumnIndex, SymbolExtensions.GetPropertyPair(parameterName), setParameter: setParameter, parseCSVString: parseCSVString);
        }

        private void Add(int csvColumnIndex, SymbolPair symbolPair, Action<T, string> setParameter = null, Func<string, string> parseCSVString = null)
        {
            if (setParameter != null || parseCSVString != null)
                CSVParameterMappingList.Add(new CSVParameterMappingCallback<T>(csvColumnIndex, symbolPair, setParameter: setParameter, parseCSVString: parseCSVString));
            else
                CSVParameterMappingList.Add(new CSVParameterMapping(csvColumnIndex, symbolPair));
        }

    }
}
